home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!news
- From: watzka@stat.uni-muenchen.de (Kurt Watzka)
- Newsgroups: comp.lang.c
- Subject: Re: #include "" for large programs.
- Date: 21 Apr 1996 12:21:06 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4ld97i$qtn@sparcserver.lrz-muenchen.de>
- References: <Pine.SUN.3.92.960411195730.24973A-100000@suntan> <4krrmi$7ef@mother.usf.edu> <4krurt$fat@sparcserver.lrz-muenchen.de> <317782EB.41C6@wight.hursley.ibm.com>
- NNTP-Posting-Host: sun2.lrz-muenchen.de
-
- Max Waterman <dwater@wight.hursley.ibm.com> writes:
-
- >Kurt Watzka wrote:
- >>
- >> gohel@csee.usf.edu (Himanshu Gohel) writes:
- >>
- >> >In article <Pine.SUN.3.92.960411195730.24973A-100000@suntan>, "Carlos Diaz (CS)" <cdiaz@eng.usf.edu> writes:
- >>
- >> >The way to avoid multiple definitions (and similarly multiple inclusions
- >> >of .h files) is to do the following:
- >>
- >> >#ifndef __MYHEADERFILE__
- >> >#define __MYHEADERFILE__
- >> > ...all your header file stuff here...
- >> >#endif
- >>
- >> Change this to something not using macro names starting with a
- >> double underscore and an upper case letter and I will happily
- >> agree with you.
-
- >Why not an uppercase letter? I user
- >#ifndef INCLUDED_MY_FUNCTION
- >#define INCLUDED_MY_FUNCTION
-
-
- "INCLUDED_MY_FUNCTION" does not start with a double underscore, much less
- with a double underscore _and_ an uppercase letter. Because I dislike
- typing, I tend to use "INCL_MY_FUNCTION", but "INCLUDED_MY_FUNCTION" does
- not start with a double underscore, so ...
-
- >> There also is a non zero chance that the stuff defined in the
- >> header file will be underfined in your compilation module that
- >> includes such a header.
-
- >For type definitions, that is what the header file is for.
-
- I was talking about the chance that the implementor of a system header
- file that is included before the header using "__MYHEADERFILE__" is
- included has defined "__MYHEADERFILE__", so that the contents of
- the header file will never be seen.
-
- >> Try something like
- >>
- >> #if defined(GLOBALS)
- >> #define GLOBAL
- >> #else
- >> #define GLOBAL extern
- >> #endif
- >>
- >> GLOBAL const answer
- >> #if defined(GLOBALS)
- >> = 42;
- >> #else
- >> ;
- >> #endif
- >>
- >> Be sure to define "GLOBALS" in exactly one compilation unit that includes
- >> a header file with that construct.
-
- >Don't see any point in GLOBAL - why not 'extern'.
-
- There is no technical need for leaving out "global" in the actual definition,
- as long as there is an initialization in exactly one compilation unit. The
- main purpose for this construct is:
-
- a) An initialization is not needed for "GLOBAL" variables.
- b) Documentation.
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
-